package com.example.demo2.common.controller;

import com.example.demo2.common.api.Result;
import com.example.demo2.common.utils.ResultGenerator;

/**
 * @Author 胡亚伟
 * @Date 2025-06-10
 * @version 1.0
 * @注释
 */

public class BaseController {

    protected final static int LENGTH_1 = 1;
    protected final static int LENGTH_4 = 4;
    protected final static int LENGTH_5 = 5;
    protected final static int LENGTH_8 = 8;
    protected final static int LENGTH_9 = 9;
    protected final static int LENGTH_10 = 10;
    protected final static int LENGTH_12 = 12;
    protected final static int LENGTH_20 = 20;
    protected final static int LENGTH_30 = 30;
    protected final static int LENGTH_50 = 50;

    public Result<?> ok() {
        return ResultGenerator.genSuccessResult();
    }

    public Result<?> ok(String message) {
        return ResultGenerator.genSuccessResult(message);
    }

    public static <T> Result<T> ok(T data) {
        return ResultGenerator.genSuccessResult(data);
    }

    public static <T> Result<T> ok(String message, T data) {
        return ResultGenerator.genSuccessResult(message, data);
    }

    public Result<?> fail() {
        return ResultGenerator.genFailResult("");
    }

    public Result<?> fail(String message) {
        return ResultGenerator.genFailResult(message);
    }

    public Result<?> unauthorized(String message) {
        return ResultGenerator.genFailResult(message, 401);
    }

    public Result<?> unjurisdiction(String message) {
        return ResultGenerator.genFailResult(message, 403);
    }

    protected boolean isHasMore(int currentPage, int limit, long totalCount) {
        if (currentPage <= 0) {
            currentPage = 1;
        }
        if (currentPage * limit < totalCount) {
            return true;
        }
        return false;
    }
}
